package action.contract;

import java.util.List;

import model.company.Companybasic;
import model.company.Companycontact;
import model.company.Companypledger;
import model.contract.Contractensure;
import model.contract.Contractmortgage;
import model.contract.Contractpledge;
import model.dropdown.DCommon;
import model.personal.Personalbasic;
import service.contract.ContractService;
import service.contract.ShowContractService;
import core.action.BaseAction;
import exception.Exceptions;

public class ShowContractRelationDetailAction extends BaseAction{
	private Integer ensureid;//接收前台传过来的Id
	private Integer mortgageid;
	private Integer pledgeid;
	private ShowContractService showContractService;
	private ContractService contractService;
	private Contractensure contractensure;
	private Contractmortgage contractmortgage;
	private Contractpledge contractpledge;
	private Companypledger things;
	private String customname;
	private String codetype;
	private String customcode;
	private String address;
	private String phone;
	
	
	public String execute(){
		return "success";
	}
	public String ShowEnsureDetail() throws Exceptions{
		contractensure=showContractService.get_htEnsure(ensureid);
		if(contractensure.getCustomensuretype().equals("2")){
			Companybasic company=contractService.get_companybasic(contractensure.getCustomensureid());
			customname=company.getName();
			List<DCommon> codetypelist=contractService.getIdtypeList();
			for(DCommon type:codetypelist){
				if(type.getId().equals(company.getRegcertificates())){
					setCodetype(type.getName());
				}
			}
			customcode=company.getRegcertificates().toString();
			address=company.getRegaddress();
			Companycontact contact=contractService.get_companycontact(contractensure.getCustomensureid());
			phone=contact.getTelephone();
		}else if(contractensure.getCustomensuretype().equals("1")){
			Personalbasic personal=contractService.get_personalbasic(contractensure.getCustomensureid());
			customname=personal.getName();
			List<DCommon> codetypelist=contractService.getIdtypeList();
			for(DCommon type:codetypelist){
				if(type.getId().equals(personal.getCertificatetype())){
					codetype=type.getName();
				}
			}
			customcode=personal.getCertificatenumber();
			address=personal.getCurrentresidentialaddress();
			phone=personal.getHomephone();
		}
		successResultValue="../show/showEnsureDetail";
		return "function";
	}
	public String ShowMortgageDetail() throws Exceptions{
		contractmortgage=showContractService.get_htMortgage(mortgageid);
		if(contractmortgage.getCustommortgagetype().equals("2")){
			Companybasic company=contractService.get_companybasic(contractmortgage.getCustommortgageid());
			customname=company.getName();
			List<DCommon> codetypelist=contractService.getIdtypeList();
			for(DCommon type:codetypelist){
				if(type.getId().equals(company.getRegcertificates())){
					setCodetype(type.getName());
				}
			}
			customcode=company.getRegcertificates().toString();
			address=company.getRegaddress();
			Companycontact contact=contractService.get_companycontact(contractmortgage.getCustommortgageid());
			phone=contact.getTelephone();
		}else if(contractmortgage.getCustommortgagetype().equals("1")){
			Personalbasic personal=contractService.get_personalbasic(contractmortgage.getCustommortgageid());
			customname=personal.getName();
			List<DCommon> codetypelist=contractService.getIdtypeList();
			for(DCommon type:codetypelist){
				if(type.getId().equals(personal.getCertificatetype())){
					codetype=type.getName();
				}
			}
			customcode=personal.getCertificatenumber();
			address=personal.getCurrentresidentialaddress();
			phone=personal.getHomephone();
		}
		things=contractService.get_customthings(contractmortgage.getThingsid());
		successResultValue="../show/showMortgageDetail";
		return "function";
	}
	public String ShowPledgeDetail() throws Exceptions{
		contractpledge=showContractService.get_htPledge(pledgeid);
		if(contractpledge.getCustompledgetype().equals("2")){
			Companybasic company=contractService.get_companybasic(contractpledge.getCustompledgeid());
			customname=company.getName();
			List<DCommon> codetypelist=contractService.getIdtypeList();
			for(DCommon type:codetypelist){
				if(type.getId().equals(company.getRegcertificates())){
					setCodetype(type.getName());
				}
			}
			customcode=company.getRegcertificates().toString();
			address=company.getRegaddress();
			Companycontact contact=contractService.get_companycontact(contractpledge.getCustompledgeid());
			phone=contact.getTelephone();
		}else if(contractpledge.getCustompledgetype().equals("1")){
			Personalbasic personal=contractService.get_personalbasic(contractpledge.getCustompledgeid());
			customname=personal.getName();
			List<DCommon> codetypelist=contractService.getIdtypeList();
			for(DCommon type:codetypelist){
				if(type.getId().equals(personal.getCertificatetype())){
					codetype=type.getName();
				}
			}
			customcode=personal.getCertificatenumber();
			address=personal.getCurrentresidentialaddress();
			phone=personal.getHomephone();
		}
		things=contractService.get_customthings(contractpledge.getThingsid());
		successResultValue="../show/showPledgeDetail";
		return "function";
	}
	
	//--------------GET/SET-------------//
	public Contractensure getContractensure() {
		return contractensure;
	}
	public void setContractensure(Contractensure contractensure) {
		this.contractensure = contractensure;
	}
	public Contractmortgage getContractmortgage() {
		return contractmortgage;
	}
	public void setContractmortgage(Contractmortgage contractmortgage) {
		this.contractmortgage = contractmortgage;
	}
	public Contractpledge getContractpledge() {
		return contractpledge;
	}
	public void setContractpledge(Contractpledge contractpledge) {
		this.contractpledge = contractpledge;
	}
	public Companypledger getThings() {
		return things;
	}
	public void setThings(Companypledger things) {
		this.things = things;
	}
	public String getCustomname() {
		return customname;
	}
	public void setCustomname(String customname) {
		this.customname = customname;
	}
	public String getCustomcode() {
		return customcode;
	}
	public void setCustomcode(String customcode) {
		this.customcode = customcode;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public Integer getEnsureid() {
		return ensureid;
	}
	public void setEnsureid(Integer ensureid) {
		this.ensureid = ensureid;
	}
	public Integer getMortgageid() {
		return mortgageid;
	}
	public void setMortgageid(Integer mortgageid) {
		this.mortgageid = mortgageid;
	}
	public Integer getPledgeid() {
		return pledgeid;
	}
	public void setPledgeid(Integer pledgeid) {
		this.pledgeid = pledgeid;
	}

	public ShowContractService getShowContractService() {
		return showContractService;
	}

	public void setShowContractService(ShowContractService showContractService) {
		this.showContractService = showContractService;
	}

	public ContractService getContractService() {
		return contractService;
	}

	public void setContractService(ContractService contractService) {
		this.contractService = contractService;
	}
	public String getCodetype() {
		return codetype;
	}
	public void setCodetype(String codetype) {
		this.codetype = codetype;
	}

}
